<?php
namespace EWeiLink\JuPai\Console;

use Illuminate\Console\Command;

/**
 * Created by PhpStorm.
 * User: Allen
 * Date: 2017/2/14
 * Time: 14:44
 */
class EnvConfigure extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'jupai:setEnv
                            {--with-plugin=}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Configure env';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $path = base_path();
        $env = $path . '/' . '.env';
        // 下面这段代码得优化，写的不忍直视
        $target = "WX_CLIENT_ID_DeadTime=1200";
        $fileCont = file_get_contents($env);
        $targetIndex = strpos($fileCont, $target);
        if ($targetIndex !== false) {
            echo "success";
            exit;
        }
        $boo1 = file_put_contents($env, PHP_EOL."WX_CLIENT_ID_DeadTime=1200", FILE_APPEND);
        if ($boo1) {
            echo "success";
        } else {
            echo "false";
        }
    }
}
